package com.oig.sys.base.dao;

import com.oig.sys.base.entity.TbCountry;
import com.oig.sys.base.vo.CountryVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbCountryDao extends JpaRepository<TbCountry, String>, JpaSpecificationExecutor<TbCountry> {


	@Query("from TbCountry c where c.code=:code")
	TbCountry getByCode(@Param("code") String code);

	@Query("from TbCountry c where c.applyCode=:applyCode")
	TbCountry getByApplyCode(@Param("applyCode") String applyCode);

	@Query("from TbCountry c where c.name=:name")
	TbCountry getByName(@Param("name") String name);

	@Query("from TbCountry c where c.isoCode=:isoCode")
	TbCountry getByIsoCode(@Param("isoCode") String isoCode);

	@Query("from TbCountry c where c.name in(:nameList) and c.areaType='1'")
	List<TbCountry> findCountriesByNames(@Param("nameList") List<String> nameList);

	@Query("from TbCountry c where c.applyCode in(:applyCodeList)")
	List<TbCountry> findCountriesByApplyCodes(@Param("applyCodeList") List<String> applyCodeList);

	@Query("select new com.oig.sys.base.vo.CountryVo(c.code,c.name,c.enName,c.status,c.isoCode,c.groupCode,c.shortCode,c.areaType,c.parentCode,c.subIndex,c.applyCode) " +
			" from TbCountry c where c.code=:code")
	CountryVo getVoByCode(@Param("code") String code);
	

	@Query("select new com.oig.sys.base.vo.CountryVo(c.code,c.name,c.enName,c.status,c.isoCode,c.groupCode,c.shortCode,c.areaType,c.parentCode,c.subIndex,c.applyCode) " +
			" from TbCountry c where c.parentCode=:parentCode")
	List<CountryVo> findByParentCode(@Param("parentCode")String parentCode);

}
